package zzhyc.keystore

import android.Manifest
import android.content.DialogInterface
import android.content.Intent
import android.content.pm.PackageManager
import android.graphics.Color
import android.os.Bundle
import android.util.Log
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import com.qq.e.comm.managers.GDTAdSdk

private const val TAG = "HLYActivity"

//ylh页面
class HLYActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_hlyactivity)
        Log.i(TAG, "onCreate: ")
        initPermission()
    }

    private fun initPermission() {
        if (ContextCompat.checkSelfPermission(
                this, Manifest.permission.ACCESS_COARSE_LOCATION
            ) != PackageManager.PERMISSION_GRANTED
        ) {
            ActivityCompat.requestPermissions(
                this, arrayOf(Manifest.permission.ACCESS_COARSE_LOCATION), 520
            )
        } else {
            initSdk()
        }
    }

    private fun initSdk() {
        GDTAdSdk.initWithoutStart(this, HLYKey.HLY_APP_ID)
        GDTAdSdk.start(object : GDTAdSdk.OnStartListener {
            override fun onStartSuccess() {
                // 推荐开发者在onStartSuccess回调后开始拉广告
                startActivity(Intent(this@HLYActivity, HLYSplashActivity::class.java))
                finish()
            }

            override fun onStartFailed(p0: Exception?) {
                Log.e(TAG, "onStartFailed-- ${p0?.message}");
            }
        })
    }

    override fun onRequestPermissionsResult(
        requestCode: Int, permissions: Array<out String>, grantResults: IntArray
    ) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults)
        when (requestCode) {
            520 -> {
                initSdk()
                return
            }
        }
    }
}